<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateKfRoles extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /**
         * 权限说明
         * 如果是 web-品牌角色 品牌Id + shopId(0) + type(1)
         * 如果是 web-门店角色 品牌Id + shopId + type(1)
         * 如果是 pos-门店角色 品牌Id + shopId + type(2)
         */
        Schema::create('roles', function (Blueprint $table) {
            $table->id();
            $table->string("name", 20)->comment("角色名");
            $table->unsignedInteger("brandId")->default(0)->comment("品牌id");
            $table->unsignedInteger("shopId")->default(0)->comment("店铺id");
            $table->unsignedTinyInteger('type')->default(0)->comment("默认0 1web 2pos");
            $table->unsignedTinyInteger("status")->default(0)->comment("状态,0:正常,1:停用,2:其他");
//            $table->unsignedTinyInteger('platform')->default(0)->comment("默认0 1:B端-品牌端 2:B端-门店端 3:POS ");   // 不需要
            $table->unsignedTinyInteger('isDeleted')->default(0)->comment("是否删除 0：未删除，1：已删除");

            $table->integer("createdAt")->comment("创建时间");
            $table->integer("updatedAt")->comment("修改时间");
            $table->index("shopId", "idx_shop_id");
            $table->index("createdAt", "idx_created_at");

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}roles` COMMENT = '角色表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('roles');
    }
}
